package model.analyzer;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class WordTreeGen {
	public static void main(String[] args) throws IOException {
		Pattern p = Pattern.compile("[A-Z]*[a-z]+");
		File f = new File("./wordList/words.english");
		System.out.println(f.exists());
		Scanner scanner = new Scanner(
				new FileInputStream(new File("./wordList/words.english")));
		//int count = 100;
		WordTree tree = new WordTree();
		String word = null;
		try {
			while((word = scanner.nextLine()) != null) {//count > 0) {
				//--count;
				Matcher mtcher = p.matcher(word);
				if(mtcher.matches()) {
					tree.insert(word);
				}
			}
		} catch (NoSuchElementException e) {
			//over
		}
		f = new File("./wordtree.dat");
		if(!f.exists()) {
			f.createNewFile();
		}
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f));
		out.writeObject(tree);
		out.close();
	}
}
